"use strict";

/*
 * MikoPBX - free phone system for small business
 * Copyright © 2017-2023 Alexey Portnov and Nikolay Beketov
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program.
 * If not, see <https://www.gnu.org/licenses/>.
 */

/* global systemDiagnosticLogs */

/**
 * Represents the update log view worker object.
 *
 * @module updateLogViewWorker
 */
var updateLogViewWorker = {
  /**
   * Time in milliseconds before fetching new request.
   * @type {number}
   */
  timeOut: 3000,

  /**
   * The id of the timer function for the worker.
   * @type {number}
   */
  timeOutHandle: 0,

  /**
   * Error count for tracking errors.
   * @type {number}
   */
  errorCounts: 0,

  /**
   * Initializes the update log view worker.
   */
  initialize: function initialize() {
    updateLogViewWorker.restartWorker();
  },

  /**
   * Restarts the update log view worker.
   */
  restartWorker: function restartWorker() {
    window.clearTimeout(updateLogViewWorker.timeoutHandle);
    updateLogViewWorker.worker();
  },

  /**
   * Worker function for fetching the request.
   */
  worker: function worker() {
    systemDiagnosticLogs.updateLogFromServer();
    updateLogViewWorker.timeoutHandle = window.setTimeout(updateLogViewWorker.worker, updateLogViewWorker.timeOut);
  },

  /**
   * Stops the update log view worker.
   */
  stop: function stop() {
    window.clearTimeout(updateLogViewWorker.timeoutHandle);
  }
};
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9TeXN0ZW1EaWFnbm9zdGljL3N5c3RlbS1kaWFnbm9zdGljLWluZGV4LXNob3dsb2dzLXdvcmtlci5qcyJdLCJuYW1lcyI6WyJ1cGRhdGVMb2dWaWV3V29ya2VyIiwidGltZU91dCIsInRpbWVPdXRIYW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